package b.acct.test

import akka.NotUsed
import akka.http.scaladsl.model.Uri.Path
import akka.http.scaladsl.model.{HttpRequest, HttpResponse, StatusCodes, Uri}
import akka.stream.scaladsl.Flow
import org.squbs.unicomplex.{FlowDefinition, WebContext}

/**
  * Created by lenovo on 2016/12/31.
  */
class SampleServer extends FlowDefinition with WebContext {
  override def flow: Flow[HttpRequest, HttpResponse, NotUsed] = Flow[HttpRequest].map {
      case HttpRequest(_, Uri(_, _, Path(s), _, _), _, _, _) if s == s"/$webContext/ping" =>
        HttpResponse(StatusCodes.OK, entity = "pong")
      case HttpRequest(_, Uri(_, _, Path(s), _, _), _, _, _) =>
        HttpResponse(StatusCodes.NotFound, entity = s"Path[$s] not found!")
      case _ =>
        HttpResponse(StatusCodes.NotFound, entity = "Path not found!")
    }
  }
